package com.ziyear.servlet;

import com.ziyear.domain.Prep;
import com.ziyear.service.PrepService;
import com.ziyear.service.impl.PrepServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

/**
 * 功能描述 : 用户付款
 *
 * @author Ziyear
 */
public class PayServlet extends HttpServlet {
    private static final long serialVersionUID = 1L;

    @Override
	protected void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        Integer prepId = Integer.valueOf(request.getParameter("prepId"));
        PrepService prepService = new PrepServiceImpl();
        Prep prep = prepService.getById(prepId);

        prep.setWay(true);
        int recordNumber = prepService.update(prep);
        PrintWriter out = response.getWriter();
        if (recordNumber == 1) {
            out.write(
                    "<script>alert('付款成功！');" + "window.location.href='MyPrepServlet'</script>");
        } else {
            out.write("<script>alert('很抱歉,付款失败！');" + "window.location.href='MyPrepServlet'</script>");
        }
        out.close();
	}


    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        // TODO Auto-generated method stub
        doGet(request, response);
    }

}
